/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package entities;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;

/**
 *
 * @author Thibault
 */
@Entity
@NamedQueries({
    @NamedQuery(name = "UserProject.findByLoginAndPassword",
    query = "SELECT u FROM UserProject u WHERE u.mail = :login AND u.password = :password"),
    @NamedQuery(name = "UserProject.isMailAlreadyUsed",
    query = "SELECT u FROM UserProject u WHERE u.mail = :mail"),
    @NamedQuery(name = "UserProject.getListAriticleWithBidForUser",
    query = "SELECT DISTINCT b.article FROM Bid b WHERE b.bidder.id = :id")
})
public class UserProject implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    private String firstName;
    private String lastName;
    @Column(unique = true)
    private String mail;
    private String password;
    @OneToMany(targetEntity = Address.class, mappedBy = "owner", cascade = CascadeType.PERSIST, fetch = FetchType.EAGER)
    private List<Address> adresses = new ArrayList<Address>();
    @OneToMany(targetEntity = Article.class, mappedBy = "seller", cascade = CascadeType.PERSIST, fetch = FetchType.EAGER)
    private List<Article> articles = new ArrayList<Article>();
    @OneToMany(targetEntity = Bid.class, mappedBy = "bidder", cascade = CascadeType.PERSIST, fetch = FetchType.LAZY)
    private List<Bid> bidsHistory = new ArrayList<Bid>();
    private int reputation;

    public UserProject() {
    }

    public UserProject(String firstName, String lastName, String mail, String password) {
        this.firstName = firstName;
        this.lastName = lastName;
        this.mail = mail;
        this.password = password;
        this.reputation = 10;
    }

    public Long getIdUserProject() {
        return id;
    }

    public void setIdUserProject(Long idUserProject) {
        this.id = idUserProject;
    }

    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public String getMail() {
        return mail;
    }

    public void setMail(String mail) {
        this.mail = mail;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public List<Address> getAdresses() {
        return adresses;
    }

    public void setAdresses(List<Address> adresses) {
        this.adresses = adresses;
    }

    public List<Article> getArticles() {
        return articles;
    }

    public void setArticles(List<Article> articles) {
        this.articles = articles;
    }

    public List<Bid> getBidsHistory() {
        return bidsHistory;
    }

    public void setBidsHistory(List<Bid> bidsHistory) {
        this.bidsHistory = bidsHistory;
    }

    public int getReputation() {
        return reputation;
    }

    public void setReputation(int reputation) {
        this.reputation = reputation;
    }
}
